<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="org.corolla.cloth.entity.Order"%>
<%@ page import="org.corolla.cloth.entity.ClothSize"%>
<%@ page import="org.corolla.cloth.utils.DataUtil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>购物车</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" />
<script>
	function jian(size) {
		var count = document.getElementById("chothmount_" + size).value;
		var yuan = count * 1;
		var cha = 0;
		var producttotal = document.getElementById("producttotaltxt").value;
		var allttotal = document.getElementById("allttotaltxt").value;
		var unitprice = document.getElementById("unitprice_" + size).value;
		if (count == 1) {
			document.getElementById("chothmount_" + size).value = 1;
		} else {
			count = count - 1;
			document.getElementById("chothmount_" + size).value = count;
			count = count * 1
			cha = yuan - count;
			cha = cha * 1;

			var chaprice = cha * unitprice * 1;
			var totleprice = unitprice * 1 * count;
			document.getElementById("pricelabel_" + size).innerText = Math
					.round(parseFloat(totleprice) * 100) / 100;
			document.getElementById("total_" + size).value = Math
					.round(parseFloat(totleprice) * 100) / 100;
			producttotal = producttotal * 1;
			producttotal = producttotal - chaprice;
			document.getElementById("producttotal").innerText = Math
					.round(parseFloat(producttotal) * 100) / 100;
			allttotal = allttotal * 1;
			allttotal = allttotal - chaprice;
			document.getElementById("allttotal").innerText = Math
					.round(parseFloat(allttotal) * 100) / 100;
			document.getElementById("producttotaltxt").value = Math
					.round(parseFloat(producttotal) * 100) / 100;
			document.getElementById("allttotaltxt").value = Math
					.round(parseFloat(allttotal) * 100) / 100;
		}

	}
	function jia(size) {
		var count = document.getElementById("chothmount_" + size).value * 1;
		var yuan = count * 1;
		var cha = 0;
		var producttotal = document.getElementById("producttotaltxt").value;
		var allttotal = document.getElementById("allttotaltxt").value;

		var unitprice = document.getElementById("unitprice_" + size).value;
		count = document.getElementById("chothmount_" + size).value * 1 + 1;
		document.getElementById("chothmount_" + size).value = count;
		var totleprice = unitprice * 1 * count;
		document.getElementById("pricelabel_" + size).innerText = Math
				.round(parseFloat(totleprice) * 100) / 100;
		document.getElementById("total_" + size).value = Math
				.round(parseFloat(totleprice) * 100) / 100;

		count = count * 1
		cha = count - yuan;
		cha = cha * 1;
		var chaprice = cha * unitprice * 1;

		producttotal = producttotal * 1;
		producttotal = producttotal + chaprice;
		document.getElementById("producttotal").innerText = Math
				.round(parseFloat(producttotal) * 100) / 100;
		allttotal = allttotal * 1;
		allttotal = allttotal + chaprice;

		document.getElementById("allttotal").innerText = Math
				.round(parseFloat(allttotal) * 100) / 100;
		document.getElementById("producttotaltxt").value = Math
				.round(parseFloat(producttotal) * 100) / 100;
		document.getElementById("allttotaltxt").value = Math
				.round(parseFloat(allttotal) * 100) / 100;

	}

	function carsubmit() {

		var list = document.getElementById("cardiv").getElementsByTagName(
				"input");
		var count = "";
		var total = "";
		for ( var i = 0; i < list.length; i++) {
			//判断是否为文本框

			if (list[i].id.substr(0, list[i].id.indexOf("_")) == "chothmount") {
				if (i < list.length) {
					count = count + list[i].value + "_";
				} else {
					count = count + list[i].value;
				}

			} else if (list[i].id.substr(0, list[i].id.indexOf("_")) == "total") {
				if (i < list.length) {
					total = total + list[i].value + "_";
				} else {
					total = total + list[i].value;
				}

			}

		}
		var alltotal = document.getElementById("allttotaltxt").value;
		document.getElementById("orderTotal").value = alltotal;
		document.getElementById("count").value = count;
		document.getElementById("total").value = total;
		document.getElementById("form1").submit();

	}
</script>
</head>
<body background="../images/bg/bg.jpg">
	<div class="TitleDiv">
		<font class="TitleCharFont">购物车</font>

	</div>

	<div
		style="margin-left: 23%; background-position: center; width: 70%; height: 130px; margin-top: 6%;"
		id="cardiv">
		<form id="form1" name="form1" method="post" action="updateAction">
			<%
			    if (null != session.getAttribute("orderlist")) {
			        List<Order> orderlist = (List<Order>) session.getAttribute("orderlist");

			        if (orderlist != null) {
			%>
			<table width="937" height="160" border="0">
				<tr bgcolor="#6295A2">
					<td height="48" colspan="3"><div align="center">
							<strong>服装</strong>
						</div>
					</td>
					<td width="101"><div align="center">
							<strong>单价</strong>
						</div>
					</td>
					<td width="219"><div align="center">
							<strong>数量</strong>
						</div>
					</td>
					<td width="240"><div align="center">
							<strong>小计</strong>
						</div>
					</td>
				</tr>
				<%
				    for (int i = 0; i < orderlist.size(); i++) {
				                Order order = orderlist.get(i);
				%>
				<tr>
					<td width="124" rowspan="2"><img
						<%
					if(null!=session.getAttribute("style_image")){
						%>
						src="<%=session.getAttribute("style_image").toString()%>"
						<%
					}else{
					%>
						
					src="../images/dress/man/up/xifu.png"
					 <%} %>
						width="70px;" height="70px;"></img>
					</td>
					<td width="68" valign="bottom">名称：</td>
					<td width="145" valign="bottom"><%=order.getClothStyle()%></td>
					<td rowspan="2" valign="middle" align="center"><%=DataUtil.getFormatDecimal(order.getUnitPrice())%>
						<input type="hidden" id="unitprice_<%=order.getClothSize()%>"
						name="unitprice_<%=order.getClothSize()%>"
						value="<%=DataUtil.getFormatDecimal(order.getUnitPrice())%>"></input>
					</td>
					<td rowspan="2" align="center" valign="middle"><label
						onclick="jian('<%=order.getClothSize()%>')">-</label> <input
						name="chothmount_<%=order.getClothSize()%>"
						id="chothmount_<%=order.getClothSize()%>" type="text" size="3"
						value="<%=order.getClothMount()%>" /> <label
						onclick="jia('<%=order.getClothSize()%>')"> +</label>
					</td>
					<td valign="middle" rowspan="2" align="center"><label
						id="pricelabel_<%=order.getClothSize()%>"
						name="pricelabel_<%=order.getClothSize()%>"><%=DataUtil.getFormatDecimal(order.getTotalPriceBySize())%></label>
						<input type="hidden" id="total_<%=order.getClothSize()%>"
						name="total_<%=order.getClothSize()%>"
						value="<%=DataUtil.getFormatDecimal(order.getTotalPriceBySize())%>"></input>
					</td>
				</tr>
				<tr>
					<td valign="top" height="18px;">大小：</td>
					<td valign="top"><%=order.getClothSize()%></td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<%
				    }
				        } else {
				%>
				<div algin="center">
					暂无订单！ <a href="../view/Welcome.jsp"
						style="cursor: hand; cursor: pointer;"><input type="button"
						name="Submit" value="返回首页" class="ResultButton" />
					</a>
				</div>

				<%
				    }
				    } else {
				%>
				<div algin="center">
					暂无订单！ <a href="../view/Welcome.jsp"
						style="cursor: hand; cursor: pointer;"><input type="button"
						name="Submit" value="返回首页" class="ResultButton" />
					</a>
				</div>
				<%
				    }
				%>
			</table>
			<%
			    if (null != session.getAttribute("totelprice") && null != session.getAttribute("transportfees")
			        && null != session.getAttribute("totalcountprice")) {
			%>
			<div class="ResultDiv">

				<div class="ResultContent">
					<strong>商品总价：￥<lable id="producttotal"><%=DataUtil.getFormatDecimal(Double.parseDouble(session.getAttribute("totelprice").toString()))%></lable>
						<input type="hidden" id="producttotaltxt" name="producttotaltxt"
						value="<%=session.getAttribute("totelprice").toString()%>" /> </strong> <strong>运费：￥<%=DataUtil.getFormatDecimal(Double.parseDouble(session.getAttribute("transportfees").toString()))%></strong>
					<strong>总计：￥<lable id="allttotal"><%=DataUtil.getFormatDecimal(Double.parseDouble(session.getAttribute("totalcountprice").toString()))%></lable>
						<input type="hidden" id="allttotaltxt" name="allttotaltxt"
						value="<%=DataUtil.getFormatDecimal(Double.parseDouble(session.getAttribute("totalcountprice").toString()))%>" />
						<input type="hidden" id="orderTotal" name="orderTotal"
						value="<%=DataUtil.getFormatDecimal(Double.parseDouble(session.getAttribute("totalcountprice").toString()))%>" />
					</strong> <input type="hidden" value="" id="count" name="count" /> <input
						type="hidden" value="" id="total" name="total" /> <a
						href="../view/StyleMan.jsp" style="cursor: hand; cursor: pointer;"></a>
				</div>
			</div>
			<div class="ResultuttonDiv">
				<a href="../view/StyleMan.jsp"><input name="jixumai"
					type="button" class="ResultButton" value="继续购买" /></a><input name="queding" type="button" class="ResultButton"
					value="确定提交" onclick="carsubmit()" /><a href="../view/Pay.jsp"><input id="jisuan" name="jiesuan" type="button"
					class="ResultButton" value="去 结 算" />
				</a>
			</div>
	</div>
	<%
	    }
	%>
	</form>
</body>
</html>